﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using BrokerBase.Lib.Policy;
using BrokerBase.Lib.Product;

namespace Broker.View.Converter
{
    public class PolicyAmountConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string result = null;
            double amt = 0f;
            UnitType ut = UnitType.Amt;

            if (parameter.ToString() == "Policy")
            {
                IPolicyLight policy = value as IPolicyLight;
                amt =policy==null?0: policy.Amount;
                ut = policy == null ? UnitType.Amt : policy.UnitType;
            }
            else if (parameter.ToString() == "PolicyPeriodActing")
            {
                IPolicyPeriodActing ppa = value as IPolicyPeriodActing;
                amt =ppa==null?0: ppa.Amount;
                ut = ppa == null ? UnitType.Amt : ppa.PolicyActing.Policy.Product.UnitType;
            }


            if (amt >= double.Epsilon)
            {
                if (ut == UnitType.Amt)
                {
                    result = amt.ToString("F2") + "元";
                }
                else
                {
                    int x = (int)amt;
                    result = x.ToString("d") + "份";
                }
            }

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
